


function getVideoStting(url) {
  return new Promise((reslove, reject) => {
    if (url) {
      wx.showLoading({
        title: '保存中',
        mask: true
      })
      wx.getSetting({
        success(res) {
          if(res.authSetting['scope.writePhotosAlbum'] == false){
            wx.showModal({
              title: '是否授权相册权限',
              cancelText: '取消',
              confirmText: '确认',
              success: function(res) {
                console.log(res);
                if(res.cancel) {
                  wx.openSetting({
                    writePhotosAlbum: false,
                  })
                  wx.showToast({
                    title: '保存失败',
                    icon: ''
                  })
                  wx.hideLoading()
                }else if(res.confirm){
                  wx.openSetting({
                    writePhotosAlbum: true,
                  })
                  wx.downloadFile({
                    url: url,
                    success: function (res) {
                      console.log(res)
                      var temp = res.tempFilePath
                      wx.saveVideoToPhotosAlbum({
                        filePath: temp,
                        success: function (res) {
                          reslove(res)
                        },
                        fail: function (err) {
                         
                          wx.hideLoading()
                          reject(err)
        
                        }
                      })
                    },
                    fail: function (err) {
                      wx.hideLoading()
                      // wx.utils.alert('保存失败')
                    }
                  })
                }
              }
            })
            
          }else{
          console.log(res);
          wx.downloadFile({
            url: url,
            success: function (res) {
              console.log(res)
              var temp = res.tempFilePath
              wx.saveVideoToPhotosAlbum({
                filePath: temp,
                success: function (res) {
                  reslove(res)
                },
                fail: function (err) {
                 
                  wx.hideLoading()
                  reject(err)

                }
              })
            },
            fail: function (err) {
              wx.hideLoading()
              // wx.utils.alert('保存失败')
            }
          })
        }
        },
        fail(res) {
        }
      })
    } else {
      wx.showLoading({
        title: '请稍等',
        mask: true
      })
      setTimeout(() => {
        wx.hideLoading()
      }, 1000)
    }
  })
}
module.exports = {
  getVideoStting
}